/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package game;

import java.io.Serializable;
import other.Costants;

/**
 *
 * @author alessandro
 */
public class Card implements Serializable, Comparable{
    private String state;
    private String seed;
    private int number;

    public Card(String seed, int number) {
        this.seed = seed;
        this.number = number;
        state = Costants.HOLD_BY_USER;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public String getSeed() {
        return seed;
    }

    public void setSeed(String seed) {
        this.seed = seed;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    @Override
    public int compareTo(Object o) {
        String seed1 = this.getSeed();
        String seed2 = ((Card) o).getSeed();
        int number1 = this.getNumber();
        int number2 = ((Card) o).getNumber();

        String state1 = this.getState();
        String state2 = ((Card) o).getState();

        if (state1.equals(state2)) {
            if (seed1.compareTo(seed2) < 0) {
                return -1;
            } else if (seed1.compareTo(seed2) > 0) {
                return 1;
            } else if (seed1.compareTo(seed2) == 0) {
                if (number1 > number2) {
                    return 1;
                } else if (number1 < number2) {
                    return -1;
                } else if (number1 == number2) {
                    return 0;
                }
            }
        } else if (state1.equals(Costants.HOLD_BY_USER)) {
            return 1;
        } else if (state2.equals(Costants.HOLD_BY_USER)) {
            return -1;
        }
        return 0;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null) {
            return false;
        } else if(((Card)o).getState().equals(this.state)){
            if (((Card) o).getSeed().equals(this.seed) && ((Card) o).getNumber() == this.number) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 67 * hash + (this.state != null ? this.state.hashCode() : 0);
        hash = 67 * hash + (this.seed != null ? this.seed.hashCode() : 0);
        hash = 67 * hash + this.number;
        return hash;
    }

}